package com.cn.pw.frame.service.impl;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.springframework.dao.DataAccessException;

import com.cn.pw.frame.dao.UserDao;
import com.cn.pw.frame.dao.entity.Role;
import com.cn.pw.frame.dao.entity.User;
import com.cn.pw.frame.service.UserService;

public class UserServiceImpl implements UserService {

	private UserDao userDao;
	
	@Override
	public User findUserByName(String name) throws DataAccessException {
		return userDao.findUserbyName(name);
	}
	public User findUserById(Integer id) throws DataAccessException {
		return userDao.findUserById(id);
	}
	
	@Override
	public List<User> findUsers(User user) throws DataAccessException {
		return userDao.findUsers(user);
	}

	@Override
	public void initUserRole(User user, String roleName) throws DataAccessException {
		/*Role role = userDao.findRoleByName(roleName);
		Set<Role> roles = new HashSet<Role>();
		roles.add(role);
		user.setRoles(roles);
		List<User> users = new ArrayList<User>();
		users.add(user);
		userDao.saveUser(users);*/
	}
	
	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	@Override
	public List<User> findUsers() {
		return userDao.findAllUsers();
	}

}
